using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Data;
using InfraStructureLayer;
using System.Web.UI;
using System.Reflection;

namespace WebControls
{
    public class SFGrid : GridView,IMultiLanguage
    {
        public SFGrid()
        {
            this.HeaderStyle.CssClass = "GridHeader";
            this.RowStyle.CssClass = "RowStyle";
            this.AlternatingRowStyle.CssClass = "AltRowStyle";
            this.CssClass = "GridMain";
        }
        
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {            
            base.Render(writer);
        }
        public delegate bool NeedsDataSourceDelegate();
        public event NeedsDataSourceDelegate NeedsDataSource;

        public delegate void EditDataDelegate(SFGridEventArgs e);
        public event EditDataDelegate EditData;

        public delegate void DeleteDataDelegate(SFGridEventArgs e);
        public event DeleteDataDelegate DeleteData;

        public delegate void NewDataDelegate();
        public event NewDataDelegate NewData;

        public void SetData(object parDataSource)
        {
            this.DataSource = parDataSource;
            this.DataBind();
        }
        public bool LoadGridData()
        {
            if (NeedsDataSource != null)
            {
                return NeedsDataSource();
            }
            else
            {
                return false;
            }
        }

        #region IMultiLanguage Members
        public void SetControlLanguage()
        {
            string txt = StaticMethods.GetMultilanguageString(this);
            if (txt != "")
            {
                string[] columnNames = txt.Split("|".ToCharArray());
                foreach (DataControlField dgc in this.Columns)
                {
                    dgc.HeaderText = columnNames[this.Columns.IndexOf(dgc)];
                }
                this.LoadGridData();
            }
        }

        private bool _IsProtectedForLanguageChange = false;
        public bool IsProtectedForLanguageChange
        {
            get
            {
                return _IsProtectedForLanguageChange;
            }
            set
            {
                _IsProtectedForLanguageChange = value;
            }
        }

        private bool _IsMasterPageControl = false;
        public bool IsMasterPageControl
        {
            get
            {
                return _IsMasterPageControl;
            }
            set
            {
                _IsMasterPageControl = value;
            }
        }
        #endregion
    }
    public class SFGridEventArgs : EventArgs
    {
        public object DataItem;
        public int ClickedRowIndex;
        public DataRowView DataRowView;
    }
}
